#include "EnumSerial.h"
#include "EnterDlg.h"
#include "cnComm.h"
// MainFrm.h : interface of the CMainFrame class
//

#pragma once
class CReportView;
class CDisplayView;
class CMainFrame : public CFrameWnd
{
	
protected: // create from serialization only
	CMainFrame();
	DECLARE_DYNCREATE(CMainFrame)

// Attributes
protected:
	CSplitterWnd m_wndSplitter;
	CMenu SettingMenu;
	SSerInfo m_ComPortInfoVec[32];
	COMMCONFIG m_CommConfig[32];
	UINT m_nCount;

	cnComm m_Comm;
public:
	enum eOperator { enAdjuest, enSampling };
	enum eCmdState
	{ 
		eCmd_None, 
		eCmd_Sampling_Begin, 
		eCmd_Sampling_Ready, 
		eCmd_Sampling_Read, 
		eCmd_Sampling_Process,
	};

	eCmdState mCmdState;
	eOperator mOperator;

// Operations
public:

// Overrides
public:
	virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

// Implementation
public:
	virtual ~CMainFrame();
	CReportView* GetTopPane();
	CDisplayView* GetMiddlePane();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:  // control bar embedded members
	CStatusBar      m_wndStatusBar;
	vector< unsigned char > m_ReciveBuffer;
	vector< double > mInputVec;
	CTime	m_BeginTime;
	UINT	m_nSamplingSeconds;

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()
	LRESULT OnComReceive( WPARAM wParam, LPARAM lParam );

	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnComSetting( UINT nID );
	afx_msg void OnOperatorAdjuest();
	afx_msg void OnOperatorSampling();

	void AnalyseSamplingData();
	void BeginSampling();
	size_t FindReadyPosition();
	
public:
	void NextSampling();
	afx_msg void OnTimer(UINT_PTR nIDEvent);
};